﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Utility;
using System.Data;
using Runda.EShop.Common.Entity;
using Runda.EShop.Bll;

namespace Runda.EShop.SaaS.BasManage
{
    public partial class SyncLogList :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Initialize();
            }
        }

        private void Initialize()
        {
            ddlType.BindEnum(EnumDescAttribute.GetFieldTexts(typeof(EnumHelper.SyncLogType)));

            ddlType.Items.Insert(0, new ListItem("全部", ""));
        }

        protected void lnkbtnQuery_Click(object sender, EventArgs e)
        {
            BindGrid(ConstHelper.PAGE_INIT_INDEX);
        } 
       

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }

        private void BindGrid(int PageIndex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null; 

            if (!string.IsNullOrEmpty(ddlType.SelectedValue))
            {
                parm = new SqlDbParameter();
                parm.ColumnName = "[Type]";
                parm.ColumnType = DbType.Int32;
                parm.ParameterName = "@Type";
                parm.ParameterValue = Convert.ToInt32(ddlType.SelectedValue);
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);
            }

            int RecordCount = 0;
            List<SysLogSyncEntity> list = new SystemBll().GetAll<SysLogSyncEntity>(parms, "CreatedAt DESC", AspNetPager1.PageSize, PageIndex, out RecordCount);

            gvLogList.DataSource = list;
            gvLogList.DataBind();

            AspNetPager1.RecordCount = RecordCount;
        }
    }
}